#include "header/pyramid_walkerscene.h"

// set this to 0.5 to see walker scene
#define TRANS 1.0

GeometryPtr geo;
SimpleMaterialPtr wallMat;

NodePtr createWalkerScene()
{
	Matrix m;
	
	NodePtr root = Node::create();
	
	setName(root,"walker_root");
	
	/*********************************
	* ground plane
	**********************************/

	NodePtr bottomPlane = makePlane(10000,10000,1,1);
	
	TransformPtr tbottomPlane = Transform::create();
	beginEditCP(tbottomPlane);
	m.setIdentity();
	m.setTranslate(0,100,0);
	m.setRotate(Quaternion(Vec3f(1,0,0), -M_PI/2));
	tbottomPlane->setMatrix(m);
	endEditCP(tbottomPlane);
		
	NodePtr bottomPlaneTrans = Node::create();
	beginEditCP(bottomPlaneTrans);
	bottomPlaneTrans->setCore(tbottomPlane);
	bottomPlaneTrans->addChild(bottomPlane);
	endEditCP(bottomPlaneTrans);

	wallMat = SimpleMaterial::create();
	beginEditCP(wallMat); 
	wallMat->setDiffuse(Color3f(1.0, 0.0, 0.0));
	wallMat->setTransparency(TRANS);
	endEditCP(wallMat);
	
	/*********************************
	* terrace
	**********************************/
	
	NodePtr terrace_left = createWall(500,800,2700,true);	
	NodePtr terrace_right = createWall(500,1700,2700,true);	
	NodePtr terrace_outer = createWall(1000,1250,2900,false);	
	NodePtr terrace_inner_left = createWall(400,1000,2500,false);	
	NodePtr terrace_inner_right = createWall(400,1500,2500,false);	

	/*********************************
	* passage 1
	**********************************/
	
	NodePtr passage1_left = createWall(670,1210,2175,true);	
	NodePtr passage1_right = createWall(670,1290,2175,true);	

	/*********************************
	* room 1
	**********************************/
	
	NodePtr room1_left_inner = createWall(70,1120,1820,true);	
	NodePtr room1_left_outer = createWall(270,1120,1580,true);	
	NodePtr room1_inner_left = createWall(90,1175,1850,false);	
	NodePtr room1_inner_right = createWall(90,1325,1850,false);	
	NodePtr room1_right = createWall(400,1380,1650,true);	
	NodePtr room1_outer = createWall(250,1250,1450,false);	
	
	/*********************************
	* passage 2
	**********************************/
	
	NodePtr passage2_left = createWall(300,975,1710,false);	
	NodePtr passage2_right = createWall(300,975,1790,false);	
	
	/*********************************
	* room 2
	**********************************/
	
	NodePtr room2_right_inner = createWall(90,825,1825,true);	
	NodePtr room2_right_outer = createWall(90,825,1675,true);	
	NodePtr room2_inner = createWall(300,675,1875,false);	
	NodePtr room2_left  = createWall(275,520,1750,true);	
	NodePtr room2_outer = createWall(300,675,1625,false);	
	
	
	
	geo = GeometryPtr::dcast(bottomPlane->getCore());
	beginEditCP(geo);
	geo->setMaterial(wallMat);
	endEditCP(geo);
		
	beginEditCP(root);
	root->setCore(Group::create());
	root->addChild(bottomPlaneTrans);
		
	root->addChild(terrace_left);
	root->addChild(terrace_right);
	root->addChild(terrace_outer);
	root->addChild(terrace_inner_left);
	root->addChild(terrace_inner_right);
		
	root->addChild(passage1_left);
	root->addChild(passage1_right);
		
	root->addChild(room1_left_inner);
	root->addChild(room1_left_outer);
	root->addChild(room1_right);
	root->addChild(room1_inner_left);
	root->addChild(room1_inner_right);
	root->addChild(room1_outer);
		
	root->addChild(passage2_left);
	root->addChild(passage2_right);

	root->addChild(room2_right_inner);
	root->addChild(room2_right_outer);
	root->addChild(room2_inner);
	root->addChild(room2_left);
	root->addChild(room2_outer);

		
	endEditCP(root);
	
	return root;
}

// creates a generic collision wall object

NodePtr createWall(int width, int x, int y, bool rot)
{
	Matrix m;
	
	NodePtr wallGeo = makeBox(width,20,20,1,1,1);
	
	TransformPtr twall = Transform::create();
	beginEditCP(twall);
	m.setIdentity();
	m.setTranslate(x,150,y);
	if (rot) m.setRotate(Quaternion(Vec3f(0,1,0), -M_PI/2));
	twall->setMatrix(m);
	endEditCP(twall);
		
	NodePtr wallTrans = Node::create();
	beginEditCP(wallTrans);
	wallTrans->setCore(twall);
	wallTrans->addChild(wallGeo);
	wallTrans->setActive(true);
	endEditCP(wallTrans);
	
	geo = GeometryPtr::dcast(wallGeo->getCore());
	beginEditCP(geo);
	geo->setMaterial(wallMat);
	endEditCP(geo);
		
	return wallTrans;
}
